<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Session;
class CollectDetails extends Controller{
    /****
     Class register     商品收藏
     *@
    */
    public function collect_goods(){
        $user_id = input('user_id');
        $collect_goods = Db::name('collect_goods a')
                       ->where(['a.user_id'=>$user_id])
                       ->join('shopro_goods b','a.goods_id = b.id','LEFT')
					   ->join('shopro_goods_service c','find_in_set(c.id,b.service_ids)','LEFT')
					   ->group("id")
					   ->field('b.*,c.name')
                       ->select();
        if($collect_goods){
           $arr = [
               'state'          => 1,
               'collect_goods'  => $collect_goods,
               'message'        => "请求成功"
            ]; 
           
        }else{
          $arr = [
               'state'     => 1,
			   'collect_goods'  => '',
               'message'   => "暂无收藏"
            ]; 
        }
       return json($arr);
        
    }
    /****
     Class register     店铺收藏
     *@
    */
	public function get_store_config_info($store_id){

		// 获取配置列表
		$config_list = Db::name('manystore_value')->where(array('manystore_id'=>$store_id))->field('config_id,value')->select();

		// 追加上配置项名称
		if(is_array($config_list) && count($config_list) > 0){
			foreach($config_list as $k => $v){
				$config_list[$k]['config_name'] = Db::name('manystore_config')->where(array('id'=>$v['config_id']))->value('title');
			}
		}

		return $config_list;

	} 
    public function collect_manystore(){
        $user_id = input('user_id');
        $collect_manystore = Db::name('collect_manystore a')
                       ->where(['a.user_id'=>$user_id])
                       ->join('manystore b','a.manystore_id = b.id','LEFT')
					   ->field('b.*')
                       ->select();
		foreach ($collect_manystore as $k => $v) {
			$collect_manystore[$k]['config_list'] = $this->get_store_config_info($v['id']);
		}
        if($collect_manystore){
           $arr = [
               'state'              => 1,
               'collect_manystore'  => $collect_manystore,
               'message'            => "请求成功"
            ]; 
           
        }else{
          $arr = [
               'state'     => 1,
			   'collect_manystore'  => '',
               'message'   => "请求成功"
            ]; 
        }
       return json($arr);
        
    }
      /****
     Class register     浏览记录
     *@
    */
    public function browse(){
        $user_id = input('user_id');
        $browse = Db::name('browse a')
                       ->where(['a.user_id'=>$user_id])
                       ->join('shopro_goods b','a.goods_id = b.id','LEFT')
                       ->select();

        $arr = [
            'state'          => 1,
            'browse'         => $browse,
            'message'        => "请求成功"
        ];
        return json($arr);
        
    }
    
    
}